package com.onlineauction.beans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.onlineauction.entities.Auction;
import com.onlineauction.entities.Bid;
import com.onlineauction.entities.Item;
import com.onlineauction.entities.User;

public class HomeBean implements Serializable{

	private static final long serialVersionUID = -227042487235550939L;
	
	private String username;
	private User user;
	private List<Item> myItems;
	private List<Bid> myBids;
	public List<Auction> getRecommend(String username, int maxNumber){
		List<Auction> auctions = new ArrayList<Auction>();
		List<Bid> bids = Bid.getBidsOfUser(username);
		if(bids.isEmpty()){
			return auctions;
		}
		Auction a = new Auction(bids.get(0).getAuctionID());
		List<Item> items = Item.searchItemsByCategory(new Item(a.getItemID()).getCategory());
		
		for(Item item: items){
			auctions.addAll(Auction.getLiveAuctionsOfItem(item.getItemID()));
		}
		if(auctions.size()>maxNumber){
			auctions = auctions.subList(0, maxNumber);
		}
		return auctions;
	}
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public User getUser() {
		if (user == null) {
			this.user = new User(username);
		}
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public List<Item> getMyItems() {
		if (this.username != null) {
			return Item.getItemsOfOwner(username);
		} else {
			return new ArrayList<Item>();
		}
	}

	public List<Bid> getMyBids() {
		if (this.username != null) {
			return Bid.getBidsOfUser(username);
		} else {
			return new ArrayList<Bid>();
		}
	}

}
